<?php
include("includes/config.php");

if (isset($_POST['submit']))
{
	$fehler = false;
	$fehlermeldung = "";
	
	if (empty($_POST['domain']))
	{
		$fehler = true;
		$fehlermeldung .= LANG_LOGIN_ERR_NO_DOMAIN;
		$fehlermeldung .= "<br />";
	}
	if (!isset($_POST['anonymous']))
	{
		if (empty($_POST['username']))
		{
			$fehler = true;
			$fehlermeldung .= LANG_LOGIN_ERR_NO_USER;
			$fehlermeldung .= "<br />";
		}
		if (empty($_POST['password']))
		{
			$fehler = true;
			$fehlermeldung .= LANG_LOGIN_ERR_NO_PASSWORD;
			$fehlermeldung .= "<br />";
		}
	}
	else
	{
		$_POST['username'] = "anonymous";
	}
	
	if (!empty($fehlermeldung))
	{
		$fehlermeldung = "<div style='margin-bottom:10px; color:red; font-size:12px'>{$fehlermeldung}</div>";
	}
	
	if ($fehler == false)
	{
		if(empty($_POST['port']))
		{
			$port = 21;
		}
		else
		{
			$port = $_POST['port'];
		}
		session_start();
		$_SESSION['logged_in'] = true;
		$_SESSION['domain'] = $_POST['domain'];
		$_SESSION['port'] = $port;
		$_SESSION['username'] = $_POST['username'];
		$_SESSION['password'] = $_POST['password'];
		header('Location: index.php');
	}
}
?>

<html>
	<head>
		<title>Web-FTP Login</title>
		<link rel="stylesheet" type="text/css" href="css/login.css">
	</head>
	
	<body>
		<center>
			<div id="login-box">
				<form method="post" action="login.php">
					<fieldset>
						<legend>Web-FTP Login</legend>
						<div id="login">
							<div id="login-form">
								<?php
									if (isset($fehler) && $fehler == true)
										echo $fehlermeldung;
								?>
								<label style="cursor: default">(FTP-)Domain:</label><br />
								<input 
									type="text" 
									name="domain" 
									size="25" 
									placeholder="www.example.com" />
								<input 
									type="text" 
									name="port" 
									size="1" 
									placeholder="21" /><br />
								<label style="cursor: default">Username:</label><br />
								<input 
									type="text" 
									name="username" 
									size="25" 
									placeholder="Steve Jobs" /><br />
								<label style="cursor: default">Passwort:</label><br />
								<input 
									type="password" 
									name="password" 
									size="25" 
									placeholder="••••••••" />
							</div>
							<table>
								<tr style="height: 20px">
									<td>
										<input type="checkbox" id="ssl" name="ssl" />
									</td>
									<td>
										<label for="ssl"><?php echo LANG_SSL_LOGIN; ?></label>
									</td>
								</tr>
								<tr style="height: 30px">
									<td>
										<input type="checkbox" id="anonymous" name="anonymous" />
									</td>
									<td>
										<label for="anonymous"><?php echo LANG_ANONYMOUS_LOGIN; ?></label>
									</td>
								</tr>
							</table>
							<div style="clear: both"></div>
							<input type="submit" name="submit" value="<?php echo LANG_LOGIN; ?>" />
						</div>
					</fieldset>
				</form>
			</div>
		</center>
	</body>
</html>